const express = require('express')
const noteModel = require('../db/model/noteModel');

const verifylogin = require('../middlewares/verifylogin')

const app = express()


app.post('/addnote',(req,res)=>{
    noteModel.create(req.body,(err,data)=>{
        res.render('jump.html',{name:"添加成功"});
    });
})

app.get('/delnote/:id',verifylogin,(req,res)=>{
    let id = req.params.id;
    noteModel.deleteOne({_id:id},(err,data)=>{
        if(err){
            return;
        }else{
            res.render('jump.html',{name:"删除成功"})
        }
    })

})

app.post('/updata',(req,res)=>{
    let title = req.body.title;
    let content = req.body.content;
    let id = req.body.id

    noteModel.updateOne({_id:id},{
        title,
        content
    },(err,data)=>{
        res.render('jump.html',{name:"修改成功了"});
    })
});

module.exports = app